package cn.cttic.app.mapper;

import cn.cttic.base.api.domain.BaseProduct;
import cn.cttic.base.api.domain.vo.BaseProductVo;
import cn.cttic.common.mybatis.core.mapper.BaseMapperPlus;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 产品套餐管理Mapper接口
 *
 * @author Times.Studio
 * @date 2024-05-23
 */
public interface BaseProductMapper extends BaseMapperPlus<BaseProduct, BaseProductVo> {

    @Select("<script>" +
        "select \n" +
        "	bp.*\n" +
        "from \n" +
        "	base_product bp\n" +
        "	inner join base_company_product bcp on bcp.product_id = bp.id and bcp.del_flag = 0\n" +
        "	inner join base_company bc on bc.id = bcp.company_id and bc.del_flag = 0\n" +
        "	inner join base_user bu on bu.company_id = bc.id and bu.del_flag = 0\n" +
        "where \n" +
        "	bu.id = #{appUserId}" +
        "</script>")
    List<BaseProductVo> getProductListByUser(@Param(value = "appUserId") String appUserId);

    @Select("<script>" +
        "select \n" +
        "	bp.*\n" +
        "from \n" +
        "	base_product bp\n" +
        "	inner join base_company_product bcp on bcp.product_id = bp.id and bcp.del_flag = 0\n" +
        "	inner join base_company bc on bc.id = bcp.company_id and bc.del_flag = 0\n" +
        "	inner join base_user bu on bu.company_id = bc.id and bu.del_flag = 0\n" +
        "where \n" +
        "	bu.id = #{appUserId}" +
        "</script>")
    Page<BaseProductVo> getProductPageByUser(@Param(value = "appUserId") String appUserId, Page page);

}
